package com.example.w.common.pattern;

import com.example.w.common.pojo.Order;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Data
@Component("discount")
public class DiscountPricingStrategy implements PricingStrategy{
    @Value("${pricingStrategy.discount}")
    private BigDecimal discount;

    @Override
    public BigDecimal getPricingTotal(Order order) {
        return discount != null?
                order.getTotal().multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP) : order.getTotal();
    }
}
